home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_casm / jlvesa11.zip / JLVESA09.ASM < prev    next >
Assembly Source File  |  1995-11-14  |  7KB  |  383 lines

  1. ; This routine is part of VESA SVGA -library
  2. ;
  3. ; Copyright 1994 Johannes Lehtinen
  4. ; All rights reserved
  5.  
  6. model large,c
  7. p386
  8.  
  9. include "jlvesads.asm"
  10.  
  11. extrn vesa_repos_w:far
  12.  
  13. segment jlvesa09_TEXT USE16 'CODE'
  14. assume cs:jlvesa09_TEXT
  15.  
  16. lines_left  dw ?     ; Number of lines left
  17. repo_lines  dw ?     ; Lines before reposition check
  18. l_width     dw ?     ; Movement per line (signed)
  19. l_width_u   dw ?     ; Movement per line (unsigned)
  20. counter     dw ?     ; Counter
  21. reset_c     dw ?     ; Counter reset value
  22. add_c       dw ?     ; Counter add value
  23. addition    dw ?     ; Addition value for linelength if counter full
  24. direction   db ?     ; Direction of move (-1/1 = left/right)
  25.  
  26. ; void JVLine_Draw(JVSWord x1, JVSWord y1, JVSWord x2, JVSWord y2,
  27. ;                  JVUByte color)
  28. ;
  29. ; Draws line from (x1,y1) to (x2,y2) with color color.
  30.  
  31. proc JVLine_Draw far
  32.    public JVLine_Draw
  33.  
  34.    push  bp
  35.    mov   bp,sp
  36.    push  di
  37.    push  ds
  38.    push  es
  39.  
  40.    mov   ax,JLVesa_Data       ; DS = Data segment
  41.    mov   ds,ax
  42.    mov   ax,[ds:WWSeg]
  43.    mov   es,ax                ; ES = Write window segment
  44.  
  45.    ; Check if line is horizontal
  46.  
  47.    mov   ax,[ss:bp+8]
  48.    cmp   [ss:bp+12],ax
  49.    je    horizontal_line
  50.  
  51.    ; Line is not horizontal
  52.    ; Check that y1 < y2
  53.  
  54.    ja    short y_right_order
  55.    xchg  ax,[ss:bp+12]
  56.    mov   [ss:bp+8],ax
  57.    mov   ax,[ss:bp+6]
  58.    xchg  ax,[ss:bp+10]
  59.    mov   [ss:bp+6],ax
  60.  
  61.    ; Calculate start address
  62.  
  63. y_right_order:
  64.    xor   eax,eax
  65.    xor   ebx,ebx
  66.    mov   ax,[ss:bp+8]
  67.    mov   bx,[ds:LWidth]
  68.    mul   ebx
  69.    mov   dx,[ss:bp+6]
  70.    add   eax,edx
  71.    add   eax,[ds:AStart]
  72.    mov   ecx,eax              ; ECX = start address
  73.  
  74.    ; Calculate x-movement
  75.  
  76.    mov   ax,[ss:bp+10]
  77.    sub   ax,[ss:bp+6]
  78.    cmp   ax,0
  79.    jl    short leftwards
  80.  
  81.    mov   [cs:direction],1
  82.    inc   ax
  83.    jmp   short calc_lines
  84.  
  85. leftwards:
  86.    mov   [cs:direction],-1
  87.    dec   ax
  88.  
  89.    ; Calculate number of lines
  90.  
  91. calc_lines:
  92.    mov   bx,[ss:bp+12]
  93.    sub   bx,[ss:bp+8]
  94.    inc   bx
  95.    mov   [cs:lines_left],bx
  96.  
  97.    ; Calculate x-movement per line
  98.  
  99.    mov   [cs:reset_c],bx
  100.    cwd
  101.    idiv  bx
  102.    mov   [cs:add_c],dx
  103.    mov   [cs:l_width],ax
  104.    mov   [cs:l_width_u],ax
  105.    mov   [cs:counter],dx
  106.  
  107.    ; Calculate addition value
  108.  
  109.    mov   [cs:addition],1
  110.    cmp   ax,0
  111.    je    short check_dir
  112.    mov   [cs:addition],0
  113.  
  114. check_dir:
  115.    cmp   [cs:direction],0
  116.    jg    short repos_win_first
  117.  
  118.    ; Recalculate start address if line goes leftwards
  119.  
  120. recalc_start:
  121.    xor   ebx,ebx
  122.    sub   bx,ax
  123.    mov   [cs:l_width_u],bx
  124.    sub   ecx,ebx
  125.    inc   ecx
  126.    xor   bx,bx
  127.    sub   bx,[cs:add_c]
  128.    mov   [cs:add_c],bx
  129.    mov   [cs:counter],bx
  130.  
  131.    ; Reposition window if necessary
  132.  
  133. repos_win_first:
  134.    mov   edx,ecx
  135.    cmp   [ds:WAStart],ecx
  136.    jbe   short dont_repos
  137.  
  138.    call  far vesa_repos_w
  139.  
  140. dont_repos:
  141.    mov   edi,edx
  142.    sub   edi,[ds:WAStart]
  143.  
  144.    ; Check if need to reposition window
  145.  
  146. check_repos:
  147.    mov   eax,edx
  148.    sub   eax,[ds:WAStart]
  149.    cmp   [ds:WSize],eax
  150.    ja    short dont_repos2
  151.  
  152.    ; Reposition window
  153.  
  154.    call  far vesa_repos_w
  155.    mov   edi,edx
  156.    sub   edi,[ds:WAStart]
  157.  
  158.    ; Calculate lines before next reposition check
  159.  
  160. dont_repos2:
  161.    mov   eax,[ds:WAStart]
  162.    add   eax,[ds:WSize]
  163.    sub   eax,edx
  164.    push  edx
  165.    xor   ebx,ebx
  166.    xor   edx,edx
  167.    mov   bx,[ds:LWidth]
  168.    div   ebx
  169.    pop   edx
  170.    cmp   ax,0
  171.    je    short dont_decrease
  172.  
  173.    dec   ax
  174.  
  175. dont_decrease:
  176.    mov   [cs:repo_lines],ax
  177.  
  178.    ; Calculate the length of the line
  179.  
  180. line_loop:
  181.    mov   cx,[cs:l_width_u]
  182.    mov   ax,[cs:reset_c]
  183.    cmp   [cs:counter],ax
  184.    jb    short dont_add
  185.    inc   cx
  186.    sub   [cs:counter],ax
  187.    jmp   short dont_add2
  188.  
  189.    ; Check if no side movement
  190.  
  191. dont_add:
  192.    add   cx,[cs:addition]
  193.  
  194.    ; Draw one line
  195.    ; Check if reposition check necessary
  196.  
  197. dont_add2:
  198.    cmp   [cs:repo_lines],0
  199.    je    draw_repos_line
  200.  
  201.    ; Line is on one page
  202.  
  203. on_one_page2:
  204.    mov   al,[ss:bp+14]
  205.    rep   stosb
  206.  
  207.    ; Calculate offset for next line
  208.  
  209. calc_next_line:
  210.    xor   eax,eax
  211.    mov   ax,[ds:LWidth]
  212.    add   ax,[cs:l_width]
  213.    add   edx,eax
  214.    cmp   [cs:direction],0
  215.    jg    short right_part
  216.  
  217.    mov   ax,[cs:add_c]
  218.    add   [cs:counter],ax
  219.    mov   ax,[cs:reset_c]
  220.    cmp   [cs:counter],ax
  221.    jb    short dont_add3
  222.    dec   edx
  223.  
  224. dont_add3:
  225.    mov   edi,edx
  226.    sub   edi,[ds:WAStart]
  227.    dec   [cs:lines_left]
  228.    jz    return
  229.    cmp   [cs:repo_lines],1
  230.    jbe   check_repos
  231.    dec   [cs:repo_lines]
  232.    jmp   line_loop
  233.  
  234. right_part:
  235.    mov   bx,[cs:add_c]
  236.    cmp   [cs:counter],bx
  237.    jae   short dont_add4
  238.  
  239.    inc   edx
  240.  
  241. dont_add4:
  242.    add   [cs:counter],bx
  243.    mov   edi,edx
  244.    sub   edi,[ds:WAStart]
  245.    dec   [cs:lines_left]
  246.    jz    return
  247.    cmp   [cs:repo_lines],1
  248.    jbe   check_repos
  249.    dec   [cs:repo_lines]
  250.    jmp   line_loop
  251.  
  252.    ; Check if line fits on current page (Calculate bytes left in this
  253.    ; page)
  254.  
  255. draw_repos_line:
  256.    mov   ebx,[ds:WAStart]
  257.    add   ebx,[ds:WSize]
  258.    sub   ebx,edx
  259.    cmp   bx,cx
  260.    jb    short on_two_pages
  261.    jmp   on_one_page2
  262.  
  263.    ; Line is on two pages
  264.  
  265. on_two_pages:
  266.    xchg  bx,cx                ; CX = bytes on this page
  267.    sub   bx,cx
  268.    push  bx
  269.    xor   ebx,ebx
  270.    mov   bx,cx
  271.    mov   al,[ss:bp+14]
  272.    rep   stosb
  273.  
  274.    ; Switch page
  275.  
  276.    add   edx,ebx
  277.    call  far vesa_repos_w
  278.    mov   edi,edx
  279.    sub   edi,[ds:WAStart]
  280.    sub   edx,ebx
  281.    pop   bx
  282.    mov   cx,bx
  283.    rep   stosb
  284.    jmp   calc_next_line
  285.  
  286.    ; Draw horizontal line
  287.    ; Calculate length of line in BX
  288.  
  289. horizontal_line:
  290.    mov   bx,[ss:bp+10]
  291.    sub   bx,[ss:bp+6]
  292.    cmp   bx,0
  293.    jge   short dont_switch_sign
  294.  
  295.    ; Switch sign of BX
  296.  
  297.    xor   ax,ax
  298.    sub   ax,bx
  299.    mov   bx,ax
  300.  
  301.    ; Calculate start address
  302.  
  303. dont_switch_sign:
  304.    inc   bx
  305.    mov   [cs:l_width],bx
  306.    xor   eax,eax
  307.    xor   edx,edx
  308.    xor   ecx,ecx
  309.    mov   ax,[ss:bp+8]
  310.    mov   dx,[ds:LWidth]
  311.    mul   edx
  312.  
  313.    mov   cx,[ss:bp+6]
  314.    cmp   [ss:bp+10],cx
  315.    jg    short dont_switch_x
  316.  
  317.    mov   cx,[ss:bp+10]
  318.  
  319. dont_switch_x:
  320.    add   eax,ecx
  321.    add   eax,[ds:AStart]
  322.    mov   edx,eax
  323.  
  324.    ; Check if need to reposition window
  325.  
  326.    cmp   [ds:WAStart],edx
  327.    jbe   short not_over
  328.  
  329.    call  far vesa_repos_w
  330.    jmp   short in_page
  331.  
  332. not_over:
  333.    sub   eax,[ds:WAStart]
  334.    cmp   [ds:WSize],eax
  335.    ja    short in_page
  336.  
  337.    call  far vesa_repos_w
  338.  
  339.    ; Draw pixels in this page
  340.  
  341. in_page:
  342.    mov   al,[ss:bp+14]        ; Drawing color
  343.    mov   edi,edx
  344.    sub   edi,[ds:WAStart]
  345.  
  346.    mov   cx,[cs:l_width]
  347.    mov   ebx,[ds:WSize]
  348.    sub   ebx,edi
  349.    cmp   cx,bx
  350.    jbe   short on_one_page
  351.  
  352.    ; On two pages
  353.  
  354.    add   edx,ebx
  355.    sub   [cs:l_width],bx
  356.    mov   cx,bx
  357.    rep   stosb
  358.  
  359.    call  far vesa_repos_w
  360.    mov   cx,[cs:l_width]
  361.    mov   edi,edx
  362.    sub   edi,[ds:WAStart]
  363.  
  364.    ; On one page
  365.  
  366. on_one_page:
  367.    rep   stosb
  368.  
  369.    ; Return
  370.  
  371. return:
  372.    pop   es
  373.    pop   ds
  374.    pop   di
  375.    pop   bp
  376.    retf
  377.  
  378. endp JVLine_Draw
  379.  
  380. ends
  381.  
  382. end
  383.